<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        ul,
        ol,
        li {
            list-style: none;
        }


        div ul {
            display: flex;
            position: absolute;
            bottom: 10px;
            left: 230px;
        }
        .box2 ul {
            left: 300px;
        }

        div ul li {
            width: 10px;
            height: 10px;
            border-radius: 50%;
            background-color: white;
            margin-left: 5px;
        }

        .box1 {
            position: relative;
            width: 550px;
            height: 275px;
            background-color: darkgoldenrod;
        }
        .box2{
            position: relative;
            width: 640px;
            height: 320px;
            top: 100px;
            background-color: darkgoldenrod;
        }

         section {
            width: 20px;
            height: 30px;
            color: white;
            position: absolute;

        }

        .s1 {
            top: 120px;
            left: 5px;
            background-color: aqua;
        }
        .s3 {
            top: 155px;
            left: 5px;
            background-color: aqua;
        }
        .s4 {
            top: 155px;
            right: 5px;
            background-color: aqua;
        }
        .s1 {
            top: 120px;
            left: 5px;
            background-color: aqua;
        }

        .s2 {
            top: 120px;
            right: 5px;
            background-color: aqua;
        }
    </style>
</head>

<body>
    <div class="box1">
        <ul>
            <li></li>
            <li></li>
            <li></li>
            <li></li>
        </ul>
        <section class="s1">
            < </section>
                <section class="s2">
                    >
                </section>
    </div>
    <div class="box2">
        <ul>
            <li></li>
            <li></li>
            <li></li>
        </ul>
        <section class="s3">
            < </section>
                <section class="s4">
                    >
                </section>
    </div>
</body>

</html>
<script>
    class lunbotu {
        constructor(boxEle, left, right, li) {
            this.boxEle = boxEle
            this.left = left
            this.right = right
            this.li = li
            this.time = null
            this.index = 0
            this.tu()
            this.zidong()
            this.click()
        }
        //其实是换背景图
        //渲染背景图
        tu() {
            this.boxEle.style.background = `url(pic${this.index}.jpg)`
        }
        //下一张 右
        rightEle() {
            this.index++
            if (this.index >= this.li.length) {
                this.index = 0
            }
            this.tu()
            this.lii()
        }
        leftEle() {
            this.index--
            if (this.index < 0) {
                this.index = this.li.length - 1
            }
            this.tu()
            this.lii()
        }
        //点 自动 动
        lii() {
            for (let i = 0; i < this.li.length; i++) {
                this.li[i].style.background = 'white'
            }
            this.li[this.index].style.background = 'blue'
        }
        //点击li的点
        liclick() {
            for (let i = 0; i < this.li.length; i++) {
                this.li[i].onclick = () => {
                    this.index = i
                    this.tu()
                    this.lii()
                }
            }
        }
        //添加自动的定时器
        zidong() {
            this.time = setInterval((e) => {
                this.rightEle()
            }, 2000)
        }
        //添加点击事件
        click() {
            this.liclick()
            this.right.onclick = () => {
                this.rightEle()
            }
            this.left.onclick = () => {
                this.leftEle()
            }
            //划出
            this.boxEle.onmouseout = () => {
                this.zidong()
            }
            //划入
            this.boxEle.onmouseover = () => {
                clearInterval(this.time)
            }
        }
    }
    //先获取要用到的按钮
    let boxEle = document.querySelector('.box1')//盒子
    let left = document.querySelector('.s1')//左右按钮
    let right = document.querySelector('.s2')
    let li = document.querySelectorAll('.box1>ul>li')//轮播图的点点
    let suibian = new lunbotu(boxEle, left, right, li)

    class lunbotue {
        constructor(boxEle, left, right, li) {
            this.boxEle = boxEle
            this.left = left
            this.right = right
            this.li = li
            this.time = null
            this.index = 0
            this.tu()
            this.zidong()
            this.click()
        }
        //其实是换背景图
        //渲染背景图
        tu() {
            this.boxEle.style.background = `url(pc${this.index}.jpg)`
        }
        //下一张 右
        rightEle() {
            this.index++
            if (this.index >= this.li.length) {
                this.index = 0
            }
            this.tu()
            this.lii()
        }
        leftEle() {
            this.index--
            if (this.index < 0) {
                this.index = this.li.length - 1
            }
            this.tu()
            this.lii()
        }
        //点 自动 动
        lii() {
            for (let i = 0; i < this.li.length; i++) {
                this.li[i].style.background = 'white'
            }
            this.li[this.index].style.background = 'blue'
        }
        //点击li的点
        liclick() {
            for (let i = 0; i < this.li.length; i++) {
                this.li[i].onclick = () => {
                    this.index = i
                    this.tu()
                    this.lii()
                }
            }
        }
        //添加自动的定时器
        zidong() {
            this.time = setInterval((e) => {
                this.rightEle()
            }, 2000)
        }
        //添加点击事件
        click() {
            this.liclick()
            this.right.onclick = () => {
                this.rightEle()
            }
            this.left.onclick = () => {
                this.leftEle()
            }
        }
    }
    let boxElee = document.querySelector('.box2')//盒子
    let lefte = document.querySelector('.s3')//左右按钮
    let righte = document.querySelector('.s4')
    let lie = document.querySelectorAll('.box2>ul>li')//轮播图的点点
    let suibiane = new lunbotue(boxElee, lefte, righte, lie)
</script>